/**
 * ----------------------------------------------------------------------------
 * Copyright Jens Konopka
 * 
 * Alle Rechte vorbehalten.
 * Licence: Apache 2.0
 * ----------------------------------------------------------------------------
 *
 * created on 05.03.2012 by jkonopka
 */
package de.sql.toolkit.generator;

import java.util.List;
import java.util.Map;


/**
 * @author jkonopka
 * 
 */
public class InsertScriptGenerator implements IGenerator {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3105109958471155297L;
	private String table;
	private List<Map<String, Object>> rows;

	/**
	 * @param table
	 * @param rows
	 */
	public InsertScriptGenerator(String table, List<Map<String, Object>> rows) {
		this.table = table;
		this.rows = rows;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.sql.toolkit.generator.IGenerator#generate()
	 */
	@Override
	public String generate() throws Exception {
		final StringBuilder sb = new StringBuilder();
		for (final Map<String, Object> map : rows) {
			final IGenerator generator = new InsertScriptRowGenerator(table, map);
			sb.append(generator.generate());
			sb.append("\n");
		}
		return sb.toString();
	}

}
